// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import  router from './routers'
import App from './App'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import $ from 'jquery'
import  store  from  './store'
import axios from 'axios'
axios.defaults.withCredentials=true;
//prod
// axios.defaults.baseURL = 'http://49.235.21.244/blog'   //设置基本的访问路径
//dev
axios.defaults.baseURL = 'http://localhost:9090/blog'   //设置基本的访问路径
Vue.prototype.axios = axios     // axios 不是vue的插件所以不能够 以插件的形式来使用。所以绑定在Vue上使用
import vueToTop from 'vue-totop'





Vue.config.productionTip = false

/* eslint-disable no-new */
 Vue.use(ElementUI)
 Vue.use(mavonEditor)
Vue.use(vueToTop)

//--------------------------测试权限start------------------------
//注入全局权限。
let permission ={
  visitor:"visitor",
  client:"client",
  admin:"admin",
  rootAdmin:"rootAdmin"
}
Vue.prototype.$permission=permission
//测试自定义指令。      eg： v-hasRole:admin='visitor'
Vue.directive("hasRole",{
  inserted:function (el,binding,vnode,oldVnode) {
    var arr=["visitor","client","admin","rootAdmin"]
    if (!binding.value) {    //如果指令的绑定值为null，就不需要
      return;

    }
    if (arr.indexOf(binding.value) == -1) {   //如果绑定的参数不在 给定的权限数组内，就当作没权限。
      el.parentElement.removeChild(el)
    }else {
      var needAuth = arr.indexOf(binding.value);

      console.log('按钮需要的权限===>' + needAuth)
      //从sessionStroage获取当前登录用户的权限。这里通过指令参数来模拟
      var  currentAuth =arr.indexOf(binding.arg)
        console.log("当前用户的权限 ===>"+currentAuth)
      if (!(currentAuth >= needAuth)) {
        el.parentElement.removeChild(el)
      }

    }
  }
})

//-------------测试权限end----------------------------------------------




var vm=new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
  mounted () {
    var a_idx = 0;
    $(document).ready(function($) {
      $("body").click(function(e) {
        var a = new Array("JAVA", "GO", "C#", "PHP", "Python", "JavaScript", "CSS" ,"C++", "SQL", "Ruby", "Node", "HTML");
        var $i = $("<span />").text(a[a_idx]);
        a_idx = (a_idx + 1) % a.length;
        var x = e.pageX,
          y = e.pageY;
        $i.css({
          "z-index": 2000000 ,
          "top": y - 20,
          "left": x,
          "position": "absolute",
          "font-weight": "bold",
          "color": "#ff6651"
        });
        $("body").append($i);
        $i.animate({
            "top": y - 180,
            "opacity": 0
          },
          1500,
          function() {
            $i.remove();
          });
      });
    });

  }

})
